$ () ->
	formatData = (res) ->
		_tmpArr = new Array
		j=0
		for i in res.data
			_tmpArr[j] = i.totle
			j++
		return _tmpArr

	$.get '/api/admin/desktop/get-day',(res) ->
		$("#today").html(res.data[res.data.length-1].totle)
		dateArr = new Array
		j=0
		for num in [res.data.length-1..0]
			date = new Date
			date.setDate(date.getDate()-num)
			dateArr[j] = (date.getMonth()+1) + "月" + date.getDate() + "日"
			j++
		day = echarts.init(document.getElementById('day'))
		option = 
			title: {
                text: res.data.length + "天垃圾袋使用量"
            }
			xAxis: {
                data: dateArr
            }
			series: [
				data: formatData(res)
			]

		day.setOption(option)

	$.get '/api/admin/desktop/get-week',(res) ->

		$("#this_week").html(res.data[res.data.length-1].totle)
		week = echarts.init(document.getElementById('week'))
		_tmeArr = new Array
		j=res.data.length-1
		k=0
		for num in [res.data.length-1..0]
			_tmeArr[k] = j + "周前"
			if _tmeArr[k] is "0周前"
				_tmeArr[k] = "本周"
			j--
			k++
		option = 
			title: {
                text: res.data.length + "周垃圾袋使用量"
            }
			xAxis: {
                data: _tmeArr
            }
			series: [
				data: formatData(res)
			]

		week.setOption(option)

	$.get '/api/admin/desktop/get-month',(res) ->
		$("#this_month").html(res.data[res.data.length-1].totle)
		dateArr = new Array
		j=0
		for num in [res.data.length-1..0]
			date = new Date
			date.setMonth(date.getMonth()-num)
			dateArr[j] = date.getFullYear() + "年" + (date.getMonth()+1) + "月"
			j++

		month = echarts.init(document.getElementById('month'))
		option = 
			title: {
                text: res.data.length + "个月垃圾袋使用量"
            }
			xAxis: {
                data: dateArr
            }
			series: [
				data: formatData(res)
			]

		month.setOption(option)

	$.get '/api/admin/desktop/get-year',(res) ->
		$("#this_year").html(res.data[res.data.length-1].totle)
		dateArr = new Array
		j=0
		for num in [res.data.length-1..0]
			date = new Date
			date.setFullYear(date.getFullYear()-num)
			dateArr[j] = date.getFullYear() + "年"
			j++
		# console.log dateArr
		year = echarts.init(document.getElementById('year'))
		option = 
			title: {
                text: res.data.length + "年垃圾袋使用量"
            }
			xAxis: {
                data: dateArr
            }
			series: [
				data: formatData(res)
			]

		year.setOption(option)
